package com.zy.study.controller;

import com.zy.study.service.ChatAssistant;
import dev.langchain4j.data.document.Document;
import dev.langchain4j.data.document.loader.FileSystemDocumentLoader;
import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.store.embedding.EmbeddingStoreIngestor;
import dev.langchain4j.store.embedding.IngestionResult;
import dev.langchain4j.store.embedding.inmemory.InMemoryEmbeddingStore;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class RAGController {
    @Resource
    private ChatAssistant chatAssistant;
    @Resource
    InMemoryEmbeddingStore<TextSegment> embeddingStore;

    @GetMapping(value = "/rag/add")
    public String testAdd()
    {
        Document document = FileSystemDocumentLoader.loadDocument("E:\\study\\课程资料\\4、（不用下载）其他资料\\Java基础常见面试题之简答题.pdf");
        EmbeddingStoreIngestor.ingest(document, embeddingStore);
        String result  = chatAssistant.chat("抽象类和接口的区别");
        System.out.println(result);
        return result;
    }
}
